//
//  BaseTabBarController.m
//  WuJieLive
//
//  Created by iMac on 2017/10/13.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "BaseTabBarController.h"


@interface BaseTabBarController ()<UITabBarControllerDelegate>

@property (nonatomic , strong) NSMutableArray * array;

@end

@implementation BaseTabBarController

-(NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor grayColor]} forState:(UIControlStateNormal)];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName :Color(240, 61, 55)} forState:(UIControlStateSelected)];
    
    NSArray * titleArray = @[@"首页",@"购物车",@"我"];
    NSArray * imageArray = @[@"icon_tab_首页_默认",@"icon_tab_购物车_默认",@"icon_tab_我的_默认"];
    NSArray * selectedImageArray = @[@"icon_tab_首页_选中",@"icon_tab_购物车_选中",@"icon_tab_我的_选中"];
   
    [self setController:[[HomeViewController alloc] init] withTitle:titleArray[0] image:imageArray[0] selectedImage:selectedImageArray[0]];
    [self setController:[[CartViewController alloc] init] withTitle:titleArray[1] image:imageArray[1] selectedImage:selectedImageArray[1]];
    [self setController:[[MineViewController alloc] init] withTitle:titleArray[2] image:imageArray[2] selectedImage:selectedImageArray[2]];
    
    self.delegate = self;
    self.selectedIndex = 0;
//    self.tabBar.barStyle = UIBarStyleBlack;
    self.viewControllers = self.array;
    
}

- (void)setController:(UIViewController *)controller withTitle:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImgae
{
    
    BaseNavigationController * navi = [[BaseNavigationController alloc]initWithRootViewController:controller];
    navi.tabBarItem = [[UITabBarItem alloc]initWithTitle:title image:[[UIImage imageNamed:image] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] selectedImage:[[UIImage imageNamed:selectedImgae] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]];
    [self.array addObject:navi];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
